package com.mp.approvalreq.util;

import java.math.BigDecimal;
import java.sql.PreparedStatement;

import org.apache.log4j.Logger;

public class PstmSetter {
    
    private static Logger logger = Logger.getLogger(PstmSetter.class);
    
    public static PreparedStatement setCondition(String sql,PreparedStatement pstm,Object... conditions) throws Throwable{
        for(int i=1;i<conditions.length+1;i++){
            if((conditions[i-1]) instanceof Integer){
                pstm.setInt(i, (int) (conditions[i-1]));
            }else if((conditions[i-1]) instanceof BigDecimal){
                pstm.setBigDecimal(i, (BigDecimal) (conditions[i-1]));
            }else{
                pstm.setString(i, (String) (conditions[i-1]));
            }
        }
        logger.info(Formatter.aformat(sql, conditions));
        return pstm;
    }
}
